<span xmlns:py="http://purl.org/kid/ns#" py:extends="'googlemap.kid'">

    ${get_script()}

		<input  type="hidden"
		        name="${name}"
		        class="${field_class}"
		        id="${field_id}"
		        value="${value}"
		        py:attrs="attrs"
		    />

		<script type="text/javascript">
		  function Placemarks() {
		  this.counter = 0;
		  this.map = map;
		  //this.map.setCenter(new GLatLng(37.4419, -122.1419), 13);
		  var value = ${python_value};
		  if (value)
		  {
		      this.map.setCenter(new GLatLng(value.center_lat, value.center_lng), value.zoom);
		      var point = new GLatLng(value.lat, value.lng);
		      initMarker(this, point, ${readonly});
		  }
		  else
		  {
		      if (!${readonly})
		        this.map.openInfoWindowHtml(this.map.getCenter(),  '${message}');
		      var myEventListener = GEvent.bind(this.map, "click", this, function(marker,point) {
			      this.map.disableInfoWindow();
			      if (this.counter == 0) {
				      if (point) {
				          initMarker(this, point, ${readonly})
				      }
			      }
		      })
		  }
		  GEvent.bind(this.map, "moveend", this, function() {
		     updateMarkerPos(this.marker);
		  });
		  GEvent.bind(this.map, "zoomend", this,  function() {
		     updateMarkerPos(this.marker);
		  });
		  }


		  function initialize() {
		    var placemarks = new Placemarks();
		  }
		  function initMarker(instance, point, readonly)
		  {
		      var marker = new GMarker(point, {draggable: !readonly});
		      if (!readonly) {
		          GEvent.addListener(marker, "dragstart", function() {
		            });

		          GEvent.addListener(marker, "dragend", function() {
		            updateMarkerPos(marker);
		            });
		      }
		      instance.map.addOverlay(marker);
		      instance.marker = marker;
		      updateMarkerPos(marker);
		      instance.counter++;
		  }

		  function updateMarkerPos(marker) {
		      if (marker)
		        $$('${field_id}').value = marker.getLatLng() + ':' + map.getCenter() + ':' + map.getZoom();
		  }
		</script>
</span>
